package cn.bonoon.kernel.web.views;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class BonoonExceptionResolver implements HandlerExceptionResolver{

	private static final Logger log = LoggerFactory.getLogger(BonoonExceptionResolver.class);

	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
		log.error("----------------------------------------resolveException-----------------------------------");
		log.error(ex.getMessage());
		ex.printStackTrace();
		for (StackTraceElement stackTraceElement : ex.getStackTrace()) {
			if (stackTraceElement.getMethodName().contains("invoke"))
				break;
			log.error("File={}  Line={}  Method={} ",
					new Object[] { stackTraceElement.getFileName(),
							stackTraceElement.getLineNumber(),
							stackTraceElement.getMethodName() });
		}
		return null;
	}
}
